﻿using System.Threading;
using System.Threading.Tasks;
using wt.wine.Application.Common.Interfaces;
using wt.wine.Application.Common.Models;
using wt.wine.Domain.DTOModel;

namespace wt.wine.Infrastructure.Persistence.Repository
{
    public class CheckWineResponse : ICheckWineResponse
    {
        private readonly IInternalHttpService _internalhttpservice;

        public CheckWineResponse(IInternalHttpService internalhttpservice)
        {
            _internalhttpservice = internalhttpservice;
        }

        /// <summary>
        /// 输入校准数量
        /// </summary>
        /// <param name="device"></param>
        /// <param name="num"></param>
        /// <param name="cancellationtoken"></param>
        /// <returns></returns>
        public async Task CalibrationSubmit(string device, int num, CancellationToken cancellationtoken)
        {
            await _internalhttpservice.PostJsonAsync<WineReturnModel>(Domain.Enums.ApiServiceType.JiuJi, "api/App/CalibrateActuallyOOW", new
            {
                deviceId = device,
                wineNumber = num
            }, cancellationtoken);
        }

        /// <summary>
        /// 发起校准命令
        /// </summary>
        /// <param name="device"></param>
        /// <param name="CmdType"></param>
        /// <param name="cancellationtoken"></param>
        /// <returns></returns>
        public async Task SendCheckCommand(string device, int CmdType, CancellationToken cancellationtoken)
        {
            await _internalhttpservice.PostJsonAsync<WineReturnModel>(Domain.Enums.ApiServiceType.JiuJi, "api/App/SendCommand", new
            {
                device = device,
                cmdType = CmdType
            }, cancellationtoken);
        }


        /// <summary>
        /// 发起订单的时候判断设备是否在线
        /// </summary>
        /// <param name="device"></param>
        /// <param name="CmdType"></param>
        /// <param name="cancellationtoken"></param>
        /// <returns></returns>
        public async Task<int> SendOrderGetStatus(string device, CancellationToken cancellationtoken)
        {
            var model = await _internalhttpservice.PostJsonAsync<WineReturnModel>(Domain.Enums.ApiServiceType.JiuJi, "api/App/GetState", new
            {
                deviceId = device,
            }, cancellationtoken);
            return model.resultCode;
        }

    }
}
